1. /* wait.h by K.Tsuru */
  2. #ifndef WAIT_H
  3. #define WAIT_H
  4. #define CONIO_EXIST 0 // Change '1' if your compiler has "conio.h".
  5. #include <iostream>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. using namespace std; // ver. 2.30
  9. #if CONIO_EXIST
  10. /***************************
  11. Non ANSI functions are used.
  12. It needs "conio.h"
  13. *****************************/
  14. #include <conio.h>
  15. inline void ErrorPuts(const char* msg){
  16. fprintf(stderr, "%s\n", msg);
  17. }
  18. inline void ErrorPut(const char* msg){
  19. fprintf(stderr, "%s", msg);
  20. }
  21. inline void Wait(const char* msg = NULL){
  22. if(msg != NULL) ErrorPuts(msg);
  23. ErrorPuts("Press Esc key to abort / another to continue.");
  24. if(kbhit()) getch();
  25. if( getch() == 0x1b ){ // conio.h
  26. ErrorPuts("Aborted.");
  27. exit(EXIT_FAILURE);
  28. }
  29. }
  30. inline void Ending(){
  31. ErrorPuts("Program ended. Hit any key.");
  32. if(kbhit()) getch();
  33. getch();
  34. }
  35. #else //CONIO_EXIST = 0
  36. /********************************
  37. ANSI C version
  38. Only ANSI functions are used.
  39. *********************************/
  40. inline void ErrorPuts(const char* const msg){ cerr << msg << endl; }
  41. inline void ErrorPut(const char* const msg) { cerr << msg; }
  42. inline void Wait(const char* msg = NULL){
  43. if(msg != NULL) ErrorPuts(msg);
  44. ErrorPuts("Press 'a' and <Enter> key to abort / <Enter> key to continue.");
  45. if(getchar() == 'a'){
  46. ErrorPuts("Aborted.");
  47. exit(EXIT_FAILURE);
  48. }
  49. }
  50. inline void Wait(const string& msg){
  51. Wait(msg.c_str());
  52. }
  53. inline void Ending(){
  54. ErrorPuts("Program ended. Hit any key.");
  55. getchar();
  56. }
  57. #endif // CONIO_EXIST
  58. #endif // WAIT_H

wait.h : last modifiled at 2017/02/25 10:30:42(1,589 bytes)
created at 2016/04/11 11:18:59
The creation time of this html file is 2017/10/11 16:07:52 (Wed Oct 11 16:07:52 2017).